<template>
  <div class="login">
    <img :src="imgSrc" alt="" height="100%" width="100%"/>
    <div class="loginPart">
      <p id="p1" style="font-size: 40px;color: #000000"><b style="font-family: '华文彩云'">撮合交易平台</b></p>>
      <el-form>
        <div class="inputElement">
          <el-form-item>
            <el-input v-model="formInline.username" class="input-codes" placeholder="用户名"></el-input>
          </el-form-item>

        </div>
        <div class="inputElement">
          <el-form-item>
            <el-input v-model="formInline.password" class="input-codes" placeholder="密码" show-password></el-input>
          </el-form-item>
        </div>
        <div class="inputElement">
          <el-form-item>
            <el-input v-model="formInline.code" class="input-code" placeholder="验证码"></el-input>
            <el-image :src="codeUrl" class="input-img" @click="getCodeUrl"></el-image>
          </el-form-item>
        </div>
        <div>
          <el-button style="background-color: #000000;color: #ffffff;border: #565553" type="primary" @click="login">
            登录
          </el-button>

        </div>
      </el-form>
    </div>
  </div>


</template>

<script>
export default {
  name: "LoginView",
  data() {
    return {
      imgSrc: require('../assets/sunrest.jpg'),
      formInline: {},
      codeUrl: '',

      //2属性定义
    }
  }, methods: {

    login() {
      this.axios.post("userservice/user/login", this.formInline).then(res => {
        if (res.data.code == 200) {
          this.$message.success(res.data.msg);
          sessionStorage.setItem("token", res.data.data.token);
          sessionStorage.setItem("myname", res.data.data.nickName);
          sessionStorage.setItem("uid",res.data.data.uid);
          this.$router.push("/index")
        } else {
          this.$message.error(res.data.msg);
        }
      })
    },
    getCodeUrl() {
      let uid = sessionStorage.getItem("uid");
      this.formInline.uid = uid;
      let time = new Date().getTime();
      this.codeUrl = "http://localhost:10010/userservice/user/getCodeUrl?uid=" + uid + "&time=" + time;
    }


    //3自定义方法

  }, created() {
    //4.钩子函数
    this.getCodeUrl();
  }
}
</script>

<style scoped>
/*.login{*/
/*  width: 100%;*/
/*  height: 100%;*/
/*  position: fixed;*/
/*  background-size: 100% 100%;*/
/*  background-repeat: no-repeat;*/
/*  background-image: url("../assets/67e55f5a-3afc-4674-be59-556190468ee4.jpg");*/
/*}*/
.loginPart {
  position: absolute;
  /*定位方式绝对定位absolute*/
  top: 50%;
  left: 50%;
  /*顶和高同时设置50%实现的是同时水平垂直居中效果*/
  transform: translate(-50%, -50%);
  /*实现块元素百分比下居中*/
  width: 450px;
  padding: 50px;
  background: rgba(0, 0, 0, .5);
  /*背景颜色为黑色，透明度为0.8*/
  box-sizing: border-box;
  /*box-sizing设置盒子模型的解析模式为怪异盒模型，
  将border和padding划归到width范围内*/
  box-shadow: 0px 15px 25px rgba(186, 99, 99, 0.5);
  /*边框阴影  水平阴影0 垂直阴影15px 模糊25px 颜色黑色透明度0.5*/
  border-radius: 15px;
  /*边框圆角，四个角均为15px*/
}


.loginPart .inputbox {
  position: relative;
}

.input-code {
  width: 150px;
  height: 10px;
  padding: 20px;
  text-align: left;
  display: flex;
}

.input-codes {
  width: 300px;
  height: 10px;
  padding: 20px;
  text-align: left;
  display: flex;
}

.input-img {
  width: 100px;
  height: 40px;
  position: absolute;
  top: 20px;
  left: 200px;
}

.loginPart .inputElement input {
  width: 100%;
  padding: 10px 0;
  font-size: 16px;
  color: #fff;
  letter-spacing: 1px;
  /*字符间的间距1px*/
  margin-bottom: 30px;
  border: none;
  border-bottom: 1px solid #fff;
  outline: none;
  /*outline用于绘制元素周围的线
  outline：none在这里用途是将输入框的边框的线条使其消失*/
  background: transparent;
  /*背景颜色为透明*/
  display: flex;
  align-items: center;
}


.login {
  width: 100%;
  height: 100%;

}

#p1 {
  position: absolute;
  top: 1px;
  left: 100px;
  text-align: left;
  display: flex;
}
</style>